package com.ruoyi.project.cms.controller;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.cms.domain.CmsMatterAlbum;
import com.ruoyi.project.cms.service.ICmsMatterAlbumService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 素材文件夹Controller
 * 
 * @author ruoyi
 * @date 2020-10-09
 */
@RestController
@RequestMapping("/matter/album")
public class CmsMatterAlbumController extends BaseController
{
    @Autowired
    private ICmsMatterAlbumService cmsMatterAlbumService;

    /**
     * 查询素材文件夹列表
     */
    @PreAuthorize("@ss.hasPermi('matter:album:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsMatterAlbum cmsMatterAlbum)
    {
        cmsMatterAlbum.setIsDel(Constants.SYS_NO);
        startPage();
        List<CmsMatterAlbum> list = cmsMatterAlbumService.selectCmsMatterAlbumList(cmsMatterAlbum);
        return getDataTable(list);
    }

    /**
     * 导出素材文件夹列表
     */
    @PreAuthorize("@ss.hasPermi('matter:album:export')")
    @Log(title = "素材文件夹", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CmsMatterAlbum cmsMatterAlbum)
    {
        List<CmsMatterAlbum> list = cmsMatterAlbumService.selectCmsMatterAlbumList(cmsMatterAlbum);
        ExcelUtil<CmsMatterAlbum> util = new ExcelUtil<CmsMatterAlbum>(CmsMatterAlbum.class);
        return util.exportExcel(list, "album");
    }

    /**
     * 获取素材文件夹详细信息
     */
    @PreAuthorize("@ss.hasPermi('matter:album:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsMatterAlbumService.selectCmsMatterAlbumById(id));
    }

    /**
     * 新增素材文件夹
     */
    @PreAuthorize("@ss.hasPermi('matter:album:add')")
    @Log(title = "素材文件夹", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsMatterAlbum cmsMatterAlbum)
    {
        return toAjax(cmsMatterAlbumService.insertCmsMatterAlbum(cmsMatterAlbum));
    }

    /**
     * 修改素材文件夹
     */
    @PreAuthorize("@ss.hasPermi('matter:album:edit')")
    @Log(title = "素材文件夹", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsMatterAlbum cmsMatterAlbum)
    {
        return toAjax(cmsMatterAlbumService.updateCmsMatterAlbum(cmsMatterAlbum));
    }

    /**
     * 删除素材文件夹
     */
    @PreAuthorize("@ss.hasPermi('matter:album:remove')")
    @Log(title = "素材文件夹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsMatterAlbumService.deleteAlbumByIds(ids));
    }
}
